package com.example.myapplication5;

import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.myapplication5.adapter.MyRecyclerAdapter;
import com.example.myapplication5.bean.Student;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity implements MyRecyclerAdapter.OnItemClickListener {
    private RecyclerView mRecyclerView;
    private List<Student> mList;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);
        mRecyclerView = findViewById(R.id.recyclerview);
        initData();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        gridLayoutManager.setOrientation(GridLayoutManager.HORIZONTAL);

        StaggeredGridLayoutManager staggeredGridLayoutManager =
                new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);

        mRecyclerView.setLayoutManager(staggeredGridLayoutManager);

        MyRecyclerAdapter adapter = new MyRecyclerAdapter(mList, this);
        mRecyclerView.setAdapter(adapter);
    }

    private void initData() {
        mList = new ArrayList<>();
        Student student;
        for (int i = 0; i < 31; i++) {
            student = new Student();
            student.setName("张小" + i);
            student.setNumber("00000000" + i);
            mList.add(student);
        }

        student = new Student();
        student.setName("张小xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        student.setNumber("00000eeeeeeeeeeeeeeeeeeeeeeeeeeeee000");
        mList.add(2, student);
        student = new Student();
        student.setName("张小aaaaaaaaaaaaaa");
        student.setNumber("000555555555555555555555555555555500");
        mList.add(4, student);
        student = new Student();
        student.setName("张小sssssssssssssssssssssssssssssss");
        student.setNumber("asdffdffffeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
        mList.add(7, student);
    }
    @Override
    public void onItemClick(Student student) {
        Log.e("test123", "========================" + student);
    }
}